package com.lpf.nio;

import java.io.FileInputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * 功能描述：从文件中读出数据并打印在控制台
 *
 * @author lpf
 * @date 2019/11/24 21:35
 * @version: 1.0
 **/
public class NioTest02 {

    public static void main(String[] arg) throws Exception {

        FileInputStream fileInputStream = new FileInputStream("C:\\Users\\LIUPEIFENG\\IdeaProjects\\Netty-Learning\\netty-zhanglong\\src\\main\\java\\com\\lpf\\nio\\text\\NioTest02.txt");
        FileChannel fileChannel = fileInputStream.getChannel();

        ByteBuffer byteBuf = ByteBuffer.allocate(512);

        // 读取文件内容到 ByteBuffer
        fileChannel.read(byteBuf);

        byteBuf.flip();

        while (byteBuf.hasRemaining()) {
            System.out.println((char) byteBuf.get());
        }

        fileInputStream.close();
    }
}
